package org.smth.search.indexer.impl;

import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;

import java.io.IOException;
import java.io.Reader;

public class FlagTokenStream extends TokenStream {

	private Reader reader;

	public FlagTokenStream(Reader reader) {
		this.reader = reader;
	}

	private int offset = -1;

	private int[] chars = new int[1];

	public Token next() throws IOException {
		int c;
		do {
			offset++;
			c = reader.read();
		} while (c == ' ');
		if (c == -1) {
			return null;
		} else {
			chars[0] = c;
			return new Token(new String(chars, 0, 1).toLowerCase(), offset, offset + 1);
		}

	}
}
